#include <HardwareSerial.h>
#define BAUD_RATE 115200

byte a_READCMD[7] = {187, 0, 34, 0, 0, 34, 126};
//byte a_READCMD[10] = {0xBB,0x00,0x27,0x00,0x03,0x22,0xFF,0xFF,0x4A,0x7E};
String redbufer;
byte reder;
//软串口类定义，RX 12  TX 14
//SoftwareSerial swSer(12, 14);
HardwareSerial swSer(1);


void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  swSer.begin(BAUD_RATE, SERIAL_8N1, 16, 17);
  delay(10);
  Serial.println("开始");
}

void loop() {
  if(swSer.available() > 0){
    Serial.println("收到数据"); 
      while(swSer.available()){
//      Serial.println(swSer.read(),HEX); 
    if(swSer.read() == 0xBB){
      delay(5); 
      if(swSer.read() == 0X02){
        delay(5);
        if(swSer.read() == 0X22){
          delay(5);
            if(swSer.read() == 0X00){
              delay(5);
              if(swSer.read() == 0X11){
              delay(5);
              for(int i=0;i<15;i++){
               reder = swSer.read();
               delay(5);
               if(i>2){   
                  redbufer+=char(reder);  
               } 
            }
            Serial.println("-----------");     
            Serial.println(redbufer);
            redbufer="";
            Serial.println("-----------");     
          }
        }
      }
    } 
   }
  }
}
  if(Serial.available() > 0){
    if(Serial.read()){
         swSer.write(&a_READCMD[0], 7);
          Serial.println("正在读取。。。。");
       
    }
  }

}
